﻿using System.ComponentModel;

namespace theeg.GraphWpf.Models
{
    public abstract class NotifyingObject : INotifyPropertyChanged
    {
        public bool SuppressPropertyChanged { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        public void RaisePropertyChanged(string propertyName)
        {
            if (!SuppressPropertyChanged && PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        protected void SetNotifyingField<T>(ref T field, T value, string propertyName)
        {
            if (Equals(value, field)) return;
            field = value;
            RaisePropertyChanged(propertyName);
        }
    }
}
